﻿/*

  The contents of this file are subject to the Mozilla Public License Version
  1.1 (the "License"); you may not use this file except in compliance with
  the License. You may obtain a copy of the License at 
  
           http://www.mozilla.org/MPL/ 
  
  Software distributed under the License is distributed on an "AS IS" basis,
  WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
  for the specific language governing rights and limitations under the License. 
  
  The Original Code is AST'r Framework.
  
  The Initial Developer of the Original Code is
  ALCARAZ Marc (aka eKameleon) <vegas@ekameleon.net>.
  Portions created by the Initial Developer are Copyright (C) 2004-2007
  the Initial Developer. All Rights Reserved.
  
  Contributor(s) :
  
 */
import asgard.display.ConfigurableDisplayObject;
import asgard.display.StageAlign;
import asgard.display.StageScaleMode;

import egallery.application.ControllerEngine;
import egallery.application.ModelEngine;
import egallery.application.ViewEngine;
import egallery.display.UIList;
import egallery.process.application.RunApplication;

import mars.logging.ApplicationLogger;

/**
 * The main Application class of the gallery application.
 * @author eKameleon
 */
class egallery.Application extends ConfigurableDisplayObject 
{

	/**
	 * Creates a new Application instance.
	 * @param target the movieclip reference of this display. 
	 */
	private function Application( target:MovieClip ) 
	{
		
		super( UIList.APPLICATION , target );
		
		Stage.scaleMode = StageScaleMode.NO_SCALE ;
		Stage.align     = StageAlign.TOP_LEFT ;		
		
		// Logs
		
		ApplicationLogger.initialize() ;
		
		// MVC
		
		ModelEngine.initialize() ;
		ViewEngine.initialize( this ) ;
		ControllerEngine.initialize() ;
		
		// Run the application
		
		RunApplication.getInstance().run() ;
		
	}

	/**
	 * The Application singleton reference.
	 */
	public static var application:Application ;	

	/**
	 * Main method used to launch the application with MTASC. 
	 */
	public static function main( target:MovieClip ):Void 
	{
		if (application == null) 
		{
			application = new Application( target ) ;
		}
	}

}